const axios = require('axios');
const { SocksProxyAgent } = require('socks-proxy-agent');

// 使用环境变量或配置文件来管理代理服务器地址
const proxyConfig = {
  host: process.env.PROXY_HOST || 'default_host',
  port: process.env.PROXY_PORT || 'default_port'
};

const proxy = `socks5://${proxyConfig.host}:${proxyConfig.port}`;
const proxyAgent = new SocksProxyAgent(proxy);

const apiUrl = 'https://your_api_url'; // 替换为你要请求的API地址

axios.get(apiUrl, {
  httpsAgent: proxyAgent
})
  .then(response => {
    console.log('Response:', response.data);
  })
  .catch(error => {
    if (error.code === 'ECONNREFUSED') {
      console.error('Proxy server refused the connection');
    } else if (error.response) {
      console.error('Server responded with an error:', error.response.data);
    } else {
      console.error('Error fetching data:', error.message);
    }
  });